"""
给ini文件和data文件封装起来，以便于用例的读取

"""

import os

import configparser
import pytest
import yaml

data_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "data", "data.yaml")
ini_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "config", "setting.ini")
file_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "file", "upload.jpeg")


class FileRead:
    def __init__(self):
        self.data_path = data_path
        self.ini_path = ini_path
        self.file_path = file_path

    def read_data(self):
        # 打开这个文件
        f = open(self.data_path, encoding="utf-8")
        # 读取这个文件流
        data = yaml.safe_load(f)
        # print(data)
        return data

    def read_ini(self):
        config = configparser.ConfigParser()  # 固定写法，实例化
        config.read(self.ini_path, encoding='utf-8')  # 读取这个路径下的配置文件
        return config

    def read_file(self):
        file = open(self.file_path, 'rb')  # 用二进制的方式打开文件
        return {'file': ('upload.jpeg', file, 'image/jpeg')}  # 传file类型文件的固定写法


base_data = FileRead()
a = base_data.read_data()
# print(a['json_data'])

